package com.microstation.service.impl;
import java.util.List;

import com.microstation.enums.ResultEnum;
import com.microstation.exception.ElementEmptyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.microstation.service.MenuInfoService;
import com.microstation.dao.MenuInfoDao;
import com.microstation.common.Assist;
import com.microstation.common.Result;
import com.microstation.entity.po.MenuInfo;
/**
 * MenuInfo的服务接口的实现类
 * 
 * @author 
 *
 */
@Service
public class MenuInfoServiceImpl implements MenuInfoService {
	private final Logger LOG = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private MenuInfoDao menuInfoDao;

	@Override
	public Result find(Assist assist) {
		//TODO这里可以做通过Assist做添加查询
		long results = menuInfoDao.getMenuInfoRowCount(assist);
		List<MenuInfo> result = menuInfoDao.selectMenuInfo(assist);
		return new Result(results, result);
	}
	@Override
	public MenuInfo findOne(Long id) {
		if (id == null) {
			return null;
		}
		MenuInfo result = menuInfoDao.selectMenuInfoById(id);
		return result;
	}

	@Override
	public Integer saveNotNull(MenuInfo value) {
		if (value == null) {
			return null;
		}
		if(value.getParentId() == null || value.getMenuFlag() == null || value.getSort() == null  ){
        	throw new ElementEmptyException(ResultEnum.EMPTY.getInfo());
		}
		int result = menuInfoDao.insertNotNullMenuInfo(value);
		return result;
	}
	@Override
	public Integer updateNotNullById(MenuInfo value) {
		if (value == null) {
			return null;
		}
		int result = menuInfoDao.updateNotNullMenuInfoById(value);
		return result;
	}

	@Override
	public Integer deleteById(Long id) {
		if (id == null) {
			return null;
		}
		int result = menuInfoDao.deleteMenuInfoById(id);
		return result;
	}

	@Override
	public List<MenuInfo> listByAssist(Assist assist) {
		return menuInfoDao.selectMenuInfo(assist);
	}
}